import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
  name: 'person',
  initialState: {
     personList:[
        {
            id:1,
            name:'张三',
            code:'123456789012345678',
            state:false
        }
     ]
  },
  reducers: {
    addPerson(state,action){
        state.personList.push(action.payload)
    },
    switchPerson(state,action){
        let item = state.personList.find(item=>item.id===action.payload.id)
        item.state =!item.state
    }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { addPerson,switchPerson} = counterSlice.actions

export default counterSlice.reducer